import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_app/bean/articlel/ArticleItemBean.dart';

///玩安卓接口
class FunAndroidNet {
  static Dio _dio = new Dio();
  BuildContext _context;
  Options _options;
  String baseUrl = "https://www.wanandroid.com/";

  FunAndroidNet([this._context]) {
    _options = Options(extra: {"context": _context});
    _dio = new Dio();
  }

  // static Dio _dio = new Dio(
  //   BaseOptions(
  //     baseUrl: "https://www.wanandroid.com/",
  //     headers: {
  //       'Accept': 'application/json, text/plain, */*',
  //       'Content-Type': 'application/json',
  //       'Authorization': "**",
  //       'User-Aagent': "4.1.0;android;6.0.1;default;A001",
  //       "HZUID": "2",
  //     },
  //   ),
  // );

  getHeaders() {
    return {
      'Accept': 'application/json, text/plain, */*',
      'Content-Type': 'application/json',
      'Authorization': "**",
      'User-Aagent': "4.1.0;android;6.0.1;default;A001",
      "HZUID": "2",
    };
  }

  static void init() {}

  /// 获取首页文章
  /// page 页码
  Future<List<ArticleItemBean>> getHomeData(int page) async {
    var r = await _dio.get<List>(
      "${baseUrl}article/list/$page/json",
      queryParameters: null,
      options: _options,
    );
    return r.data.map((e) => ArticleItemBean.fromJson(e)).toList();
  }
}
